﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Medianamik.Core.Security;
using Medianamik.Core;

namespace Medianamik.UI.Controls
{
    public class SecuredImageButton : ImageButton
    {
        protected override void OnPreRender(EventArgs e)
        {
            if (SecurityLevel != SecurityLevels.None)
            {
                if (!Roles.UserHasRight(NodeManager.GetNode(NodeId), SecurityLevel))
                    Enabled = false;
            }

            base.OnPreRender(e);
        }

        //Mandatory
        public Guid NodeId
        {
            get
            {
                if (ViewState["NodeId"] == null)
                    throw new ArgumentNullException("NodeId");

                return (Guid)ViewState["NodeId"];
            }
            set
            {
                ViewState["NodeId"] = value;
            }
        }

        public SecurityLevels SecurityLevel
        {
            get { return _securityLevel; }
            set { _securityLevel = value; }
        }
        SecurityLevels _securityLevel = SecurityLevels.Update; //Default
    }
}
